package com.itita.ww2.data;

import com.smartfoxserver.v2.entities.data.ISFSObject;
import com.smartfoxserver.v2.entities.data.SFSObject;

public class BuildingConfig {
	public static boolean isLoaded;
	//
	private static ISFSObject config;
	private static ISFSObject attribute;

	public static void init(ISFSObject data) {
		config = data.getSFSObject("config");
		attribute = data.getSFSObject("attribute");
		isLoaded = true;
	}

	private static final ISFSObject getBDCfgByCode(String code, int level) {
		String key = code + "_" + level;
		return attribute.getSFSObject(key);
	}

	/**
	 * 建筑是否达到了最高等级
	 */
	public static final boolean isBDLvMaximum(String code, int level) {
		return config.getSFSObject("MaxLv").getInt(code) <= level;
	}

	/**
	 * 获取建筑的升级资源
	 */
	public static final ISFSObject getBDUpgradeRes(String code, int level) {
		if (level == 0) {
			return SFSObject.newInstance();
		}
		return getBDCfgByCode(code, level).getSFSObject("upgrade_res");
	}

	/**
	 * 获取建筑(据点建筑)的升级价格
	 */
	public static final ISFSObject getBDBaseUpgradeRes(String code, int level) {
//		if (level == 0) {
//			return SFSObject.newInstance();
//		}
		return getBDCfgByCode(code, level).getSFSObject("base_upgrade_res");
	}

	/**
	 * 获取建筑升级时间
	 */
	public static final int getBDUpgradeTime(String code, int level) {
		return getBDCfgByCode(code, level).getInt("upgrade_time");
	}

	//	/**
	//	 * 获取资源建筑的容量
	//	 */
	//	public static final long getBDCapacity(String code, int level) {
	//		return getBDCfgByCode(code, level).getLong("Capacity");
	//	}

	/**
	 * 获取资源建筑每分钟涨资源量
	 */
	public static final int getBDEffect(String code, int level) {
		return getBDCfgByCode(code, level).getInt("effect");
	}

	/**
	 * 获取建筑升级前置条件
	 */
	public static final ISFSObject getBDUpgradeLimit(String code, int level) {
		ISFSObject ret = getBDCfgByCode(code, level);
		if (ret.containsKey("pre_limit")) {
			return ret.getSFSObject("pre_limit");
		} else {
			return SFSObject.newInstance();
		}
	}

	public static final ISFSObject getBuildingCfg() {
		return attribute;
	}
}
